import 'dart:async';
import 'dart:developer';
import 'package:flutter/cupertino.dart';
import 'fm_app.dart';

class FMAppInit {
  static void run() {
    var onError = FlutterError.onError; //先将 onerror 保存起来
    FlutterError.onError = (FlutterErrorDetails details) {
      onError?.call(details); //调用默认的onError
      reportErrorAndLog(details); //上报
    };
    runZoned(
          () => FMApp.run(),
      zoneSpecification: ZoneSpecification(
        // 拦截print
        print: (Zone self, ZoneDelegate parent, Zone zone, String line) {
          log(line, zone: zone, name: "Print");
        },
        // 拦截未处理的异步错误
        handleUncaughtError: (Zone self, ZoneDelegate parent, Zone zone,
            Object error, StackTrace stackTrace) {
          log(error.toString(),
              zone: zone, error: error, stackTrace: stackTrace, name: "ERROR");
        },
      ),
    );
  }
}


void collectLog(String line) {
  // ... //收集日志
}
void reportErrorAndLog(FlutterErrorDetails details) {
  // ... //上报错误和日志逻辑
}
